﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace DingTalkAgent.Web
{
    public class ConfigHelper
    {
        #region FetchCorpID Function    
        /// <summary>  
        /// 获取CorpID  
        /// </summary>  
        /// <returns></returns>  
        public static String FetchCorpID()
        {
            return FetchValue("CorpID");
        }
        #endregion

        #region FetchCorpSecret Function  
        /// <summary>  
        /// 获取CorpSecret  
        /// </summary>  
        /// <returns></returns>  
        public static String FetchCorpSecret()
        {
            return FetchValue("CorpSecret");
        }
        /// <summary>  
        /// 获取CorpSecret  
        /// </summary>  
        /// <returns></returns>  
        public static String FetchSSOSecre()
        {
            return FetchValue("SSOSecre");
        }
        /// <summary>  
        /// 获取站点地址  
        /// </summary>  
        /// <returns></returns>  
        public static String getUrlRoot()
        {
            return FetchValue("UrlRoot");
        }
        /// <summary>  
        /// 获取文件资源所在  
        /// </summary>  
        /// <returns></returns>  
        public static String getUriPath()
        {
            return FetchValue("UriPath");
        } 
        /// <summary>  
        /// 获取文件下载路径 
        /// </summary>  
        /// <returns></returns>  
        public static String getfilePath()
        {
            return FetchValue("filePath");
        }
        /// <summary>  
        /// 获取应用ID  
        /// </summary>  
        /// <returns></returns>  
        public static String getagentid()
        {
            return FetchValue("agentid");
        }
        #endregion


        /// <summary>
        /// 页面大小设置 后台
        /// </summary>
        public static int getPageSize
        {
            get { return int.Parse(FetchValue("PageSize").ToString()); }
        }
       /// <summary>
       /// 错误返回
       /// </summary>
        public static string getErrorMsg
        {
            get { return FetchValue("getErrorMsg").ToString(); }
        }
        #region FetchValue Function                
        public static String FetchValue(String key)
        {
            String value = ConfigurationManager.AppSettings[key];
            if (value == null)
            {
                throw new Exception($"{key} is null.请确认配置文件中是否已配置.");
            }
            return value;
        }
        #endregion
    }
}